| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | (function () { |
||
| 12 | .controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', function ($scope, $window, CredentialService, VaultService) { |
||
| 13 | $scope.available_exporters = []; |
||
| 14 | $scope.active_vault = VaultService.getActiveVault(); |
||
| 15 | |||
| 16 | |||
| 17 | $scope.$watch(function () { |
||
| 18 | return $window.PassmanExporter; |
||
| 19 | }, function (exporters) { |
||
| 20 | exporters = Object.keys(angular.copy(exporters)); |
||
| 21 | for (var i = 0; i < exporters.length; i++) { |
||
| 22 | var exporter = exporters[i]; |
||
| 23 | if ($window.PassmanExporter[exporter].hasOwnProperty('info')) { |
||
| 24 | $scope.available_exporters.push($window.PassmanExporter[exporter].info); |
||
| 25 | } |
||
| 26 | } |
||
| 27 | }, true); |
||
| 28 | $scope.log = []; |
||
| 29 | $scope.setExporter = function (exporter) { |
||
| 30 | exporter = JSON.parse(exporter); |
||
| 31 | $scope.selectedExporter = exporter; |
||
| 32 | }; |
||
| 33 | var _log = function (str) { |
||
| 34 | $scope.log.push(str); |
||
| 35 | }; |
||
| 36 | |||
| 37 | |||
| 38 | $scope.startExport = function () { |
||
| 39 | _log('Starting export'); |
||
| 40 | var _credentials = []; |
||
| 41 | VaultService.getVault(VaultService.getActiveVault()).then(function (vault) { |
||
| 42 | _log('Decrypting credentials'); |
||
| 43 | if (vault.hasOwnProperty('credentials')) { |
||
| 44 | if (vault.credentials.length > 0) { |
||
| 45 | for (var i = 0; i < vault.credentials.length; i++) { |
||
| 46 | var _credential = angular.copy(vault.credentials[i]); |
||
| 47 | if (_credential.hidden === 0) { |
||
| 48 | _credential = CredentialService.decryptCredential(_credential); |
||
| 49 | _credentials.push(_credential); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | $window.PassmanExporter[$scope.selectedExporter.id].export(_credentials).then(function () { |
||
| 53 | _log('Done'); |
||
| 54 | }); |
||
| 55 | } |
||
| 56 | |||
| 57 | } |
||
| 58 | }); |
||
| 59 | }; |
||
| 60 | |||
| 61 | |||
| 62 | }]); |
||
| 63 | |||
| 64 | }()); |